package com.ruoyi.technician.mapper;

import com.ruoyi.technician.domain.Technician;
import com.ruoyi.technician.vo.SelectAddNotRelevancyItemListVo;
import com.ruoyi.technician.vo.SelectTechnicianOrderResponseVo;
import com.ruoyi.technician.vo.SelectUserNotRelevancyTechnicianListVo;
import com.ruoyi.technician.vo.ServiceItems;
import com.ruoyi.technicianStatistics.vo.TechnicianStatisticsResponseVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * 技师管理Mapper接口
 * 
 * @author ruoyi
 * @date 2025-04-07
 */
public interface TechnicianMapper 
{
    /**
     * 查询技师管理
     * 
     * @param id 技师管理主键
     * @return 技师管理
     */
    public Technician selectTechnicianById(Long id);

    /**
     * 查询技师管理列表
     * 
     * @param technician 技师管理
     * @return 技师管理集合
     */
    public List<Technician> selectTechnicianList(Technician technician);

    /**
     * 新增技师管理
     * 
     * @param technician 技师管理
     * @return 结果
     */
    public int insertTechnician(Technician technician);

    /**
     * 修改技师管理
     * 
     * @param technician 技师管理
     * @return 结果
     */
    public int updateTechnician(Technician technician);

    /**
     * 删除技师管理
     * 
     * @param id 技师管理主键
     * @return 结果
     */
    public int deleteTechnicianById(Long id);

    /**
     * 批量删除技师管理
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTechnicianByIds(Long[] ids);

    @Select("select * from t_item where id = #{id}")
    ServiceItems selItemName(@Param("id") Long id);

    @Select("SELECT group_concat(u.id ORDER BY find_in_set( u.item_name, t.service_item ))  tids FROM `t_technician` t INNER JOIN `t_item`  u ON find_in_set( u.id, t.service_item )> 0 WHERE t.id = #{id} GROUP BY t.id")
    String selectItemIdByTid(@Param("id") Long id);


    List<ServiceItems> selectItem(@Param("itemIds") List<Long> itemIds);

    @Select("select user_nike_name from t_user where id =#{userId}")
    String selectUserName(@Param("userId") Long userId);

    List<SelectTechnicianOrderResponseVo> selectTechnicianOrder(@Param("tid") Long tid);

    @Select("select ifnull(sum(item_revenue)+sum(fare_revenue),0)  from t_technician_consume_detail where order_no = #{orderNo}")
    BigDecimal selectIncome(@Param("orderNo") String orderNo);

    @Update("update t_technician set service_item = #{serviceItem} where id = #{tid}")
    Integer updateItem(@Param("tid") Long tid,@Param("serviceItem") String serviceItem);

    Integer addItem(@Param("tid") Long tid,@Param("itemId") String itemId);

    @Select("select type_name from t_technician_type where  id = #{technicianType}")
    String selectTypeName(@Param("technicianType") Long technicianType);

    @Select("select broker_name from t_broker where broker_invitation_code = #{technicianInvitedCode}")
    String selectPartnerBrokerName(@Param("technicianInvitedCode") String technicianInvitedCode);

    @Select("select technician_name from t_technician where id = #{tid}")
    String selectTName(@Param("tid") Long tid);

    @Select("SELECT GROUP_CONCAT( id SEPARATOR ',' ) AS item_id FROM t_item")
    String selectAllItem();

    @Select("select id from t_item where is_shelves = 1")
    List<Long> selectAllItemId();

    List<ServiceItems> selectItemList(@Param("keyWord") String keyWord,@Param("itemIds") List<Long> itemIds);

    TechnicianStatisticsResponseVo selectTechnicainData();

    TechnicianStatisticsResponseVo selectTechnicainOnlineData();

    List<TechnicianStatisticsResponseVo> selectTechnicianTakeOrderCount();


    Technician selectPartner(@Param("partnerTel") String partnerTel);

    Technician select(@Param("userInvitationCode") String userInvitationCode);


    @Select("select count(*) from t_technician")
    Integer selectCount();

    @Select("select count(*) from t_technician where technician_sex = #{sex}")
    Integer selectCountBySex(@Param("sex") Integer sex);

    List<Technician> selectAllTechnicianList();

    List<SelectUserNotRelevancyTechnicianListVo> selectUserNotRelevancyTechnicianList(SelectAddNotRelevancyItemListVo requestVo);
}
